﻿CREATE PROCEDURE [dbo].[proc_CallCenter_Record_Create_1]
	(
		@ZuoxiID int,
		@Type nvarchar(50),
		@Tel nvarchar(50),
		@StartDate datetime,
		@EndDate datetime,
		@FileName nvarchar(50),
		@TxtFileName nvarchar(50),
		@CompanyId int
	)
AS
begin	
	--此处增加日期条件 此处是当前这条数据的生成日期 2014-01-06 Shane
	Declare @Today datetime SELECT DATEADD(DAY, CONVERT(int, @TxtFileName), '1899-12-30 00:00:00') 
	--END
	
	--Declare @n int
	--Select @n=Count(Id) From CallCenter_Record WHERE CreateDate>@Today AND FileName=@FileName
	--if(@n<=0)
	begin
		Declare @DepartmentId int,@UserName nvarchar(50),@EName nvarchar(50)
		Select @DepartmentId=DepartmentId,@UserName=UserName,@EName=EName From CallCenter Where ZXNum=@ZuoxiID AND CompanyId=@CompanyId
		
		IF NOT EXISTS (Select Id From CallCenter_Record WHERE CompanyId=@CompanyId AND CreateDate>@Today AND FileName=@FileName) Insert Into CallCenter_Record(ZuoxiID,Type,Tel,StartDate,EndDate,FileName,CreateDate,DepartmentId,UserName,EName,TxtFileName,CompanyId)
		Values(@ZuoxiID,@Type,@Tel,@StartDate,@EndDate,@FileName,GetDate(),Isnull(@DepartmentId,-1),@UserName,@EName,@TxtFileName,@CompanyId)
	end
end
	RETURN
